<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>auto cheyun cms</title>
    <!-- Data Tables -->
    <link href="<?php echo base_url(); ?>static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">

    <link href="<?php echo base_url(); ?>static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/animate.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>static/css/style.css" rel="stylesheet">

    <!-- 导入jquery -->
    <script src="<?php echo base_url(); ?>static/js/jquery-2.1.1.js"></script>

</head>

<body>
	
	<div id="wrapper">
		<!-- 左侧菜单 -->
		<?php $this->load->view('admin/common/left.html'); ?>
		<div id="page-wrapper" class="gray-bg">
			<!-- 公共头部 -->
			<?php $this->load->view('admin/common/header.html'); ?>
			<!-- content 主区域 -->
			<div class="wrapper wrapper-content">
	            <div class="row">
	                <div class="col-lg-12">
		                <div class="ibox float-e-margins">
			                <div class="ibox-title">
								<h5>角色管理</h5>

							</div>
							<div class="ibox-content">
                                <p>
                                    <button class="btn btn-primary" type="button" data-toggle="modal" data-target="#myModal"><i class="fa fa-paste"></i>添加</button></a>
                                </p>
                                <!-- 弹窗form表单 start -->
                                <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog"  aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content animated fadeIn">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                                <h4 class="modal-title">添加角色</h4>
                                            </div>
                                            <div class="modal-body">
                                                <form method="post" action="<?php echo site_url('admin/auth/post_role') ?>" class="form-horizontal" id="platform">
                                                <div class="form-group"><label class="col-sm-4 control-label">角色名称</label>
                                                    <div class="col-sm-5"><input type="text" class="form-control" name="title" placeholder="角色名称"></div>
                                                </div>
                                                <!-- <div class="form-group">
                                                    <div class="col-sm-4 col-sm-offset-2">
                                                        <button class="btn btn-primary" type="submit">保存</button>
                                                    </div>
                                                </div> -->
                                                <!-- </form> -->
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                                                <button type="submit" class="btn btn-primary">保存</button>
                                            </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                                <!-- 弹窗form表单 end -->

								<div class="table-responsive">
                                    <table class="table table-striped table-bordered table-hover dataTables-example" id="editable">
                                    <thead>
                                    <tr>
                                        <th>GID</th>
                                        <th>角色名称</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach ($roles as $k => $v): ?>
                                            <tr class="gradeA" id="<?php echo $v['id'] ?>">
                                                <td><?php echo $v['id'] ?></td>
                                                <td id="title"><?php echo $v['title'] ?></td>
                                                <td>
                                                <div class="onoffswitch">
                                                    <input type="checkbox" <?php if ($v['status']) {?>checked<?php } ?> class="onoffswitch-checkbox" ruleid="<?php echo $v['id'] ?>" id="switch_<?php echo $v['id'] ?>">
                                                    <label class="onoffswitch-label" for="switch_<?php echo $v['id'] ?>">
                                                        <span class="onoffswitch-inner"></span>
                                                        <span class="onoffswitch-switch"></span>
                                                    </label>
                                                </div>
                                                </td>
                                                <td>[<a href="<?php echo site_url('admin/auth/access/'.$v['id']) ?>">权限配置</a>]</td>
                                            </tr>
                                        <?php endforeach ?>
                                        
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th>GID</th>
                                        <th>角色名称</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </tfoot>
                                    </table>
                                </div>
							</div>
		                </div>
		            </div>
	            </div>
			</div>
            <?php $this->load->view('admin/common/footer.html'); ?>

		</div>
	</div>


    <!-- Mainly scripts -->
    <script src="<?php echo base_url(); ?>static/js/jquery-2.1.1.js"></script>
    <script src="<?php echo base_url(); ?>static/js/bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/jeditable/jquery.jeditable.js"></script>
    
    <!-- Data Tables -->
    <script src="<?php echo base_url(); ?>static/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/dataTables/dataTables.responsive.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/dataTables/dataTables.tableTools.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="<?php echo base_url(); ?>static/js/inspinia.js"></script>
    <script src="<?php echo base_url(); ?>static/js/plugins/pace/pace.min.js"></script>

    <!-- Page-Level Scripts -->
    <script>
        $(document).ready(function() {
            var oTable = $('.dataTables-example').dataTable({
                // responsive: true,
                "bPaginate": false,
                "bInfo": false,
                "bFilter":false,
                "dom": '<"clear">lfrtip',
            });

            /* Apply the jEditable handlers to the table */
            oTable.$('td[id="title"]').editable( '<?php echo site_url("admin/auth/edit_role") ?>', {
                tooltip   : "双击修改",
                event     : "dblclick",
                callback: function( sValue, y ) {
                    var aPos = oTable.fnGetPosition( this );
                    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
                },
                submitdata: function ( value, settings ) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                    };
                },

                "width": "90%",
                "height": "100%"
            } );

            $('.onoffswitch > input').each(function(){
                $(this).click(function(){
                    var disabled = 1;
                    var ruleid = $(this).attr('ruleid');
                    var ischecked = $(this).is(':checked');

                    if (ischecked) {
                        disabled = 0;
                    }
                    console.log(disabled);
                    $.ajax({
                        url: "<?php echo site_url('admin/auth/doswitch') ?>",
                        data: {ruleid:ruleid,disabled:disabled},
                        type: "POST",
                        dataType: "JSON",
                        success: function(ret){
                            console.log(ret.code);
                        }
                    })
                })
            })
        });

        function switcher(ruleid) {
            var ischecked = $('#switch_'+ruleid).is(':checked');
            console.log(ischecked);
        }
    </script>

    <style>
    body.DTTT_Print {
        background: #fff;

    }
    .DTTT_Print #page-wrapper {
        margin: 0;
        background:#fff;
    }

    button.DTTT_button, div.DTTT_button, a.DTTT_button {
        border: 1px solid #e7eaec;
        background: #fff;
        color: #676a6c;
        box-shadow: none;
        padding: 6px 8px;
    }
    button.DTTT_button:hover, div.DTTT_button:hover, a.DTTT_button:hover {
        border: 1px solid #d2d2d2;
        background: #fff;
        color: #676a6c;
        box-shadow: none;
        padding: 6px 8px;
    }

    .dataTables_filter label {
        margin-right: 5px;

    }
</style>
</body>